﻿using System;
using System.Collections.Generic;
using System.Text;
using RaisingStudio.Data.Common.Factories;
using RaisingStudio.Data.Entities;
using RaisingStudio.Data.Common;

namespace SmartDeviceProject2
{
    public class ObjectAccessor : IObjectAccessor, IObjectCreater
    {
        #region IObjectCreater Members

        public object CreateObject()
        {
            return new Issue();
        }

        public System.Collections.IList CreateObjectList()
        {
            return new List<Issue>();
        }

        #endregion

        #region IObjectAccessor Members

        public object GetValue(object instance, string name)
        {
            Issue issue = instance as Issue;
            Dictionary<string, int> dictionary = new Dictionary<string, int>();
            dictionary.Add("IssueID", 0);
            dictionary.Add("Title", 1);
            dictionary.Add("Description", 2);
            dictionary.Add("Status", 3);
            dictionary.Add("IssueType", 4);
            dictionary.Add("Owner", 5);
            dictionary.Add("Progress", 6);
            dictionary.Add("CreateTime", 7);
            dictionary.Add("Locked", 8);

            int num;
            if (dictionary.TryGetValue(name, out num)) goto L_0103;
            goto L_012c;

        L_0103:
            switch (num)
            {
                case 0: return issue.IssueID;
                case 1: return issue.Title;
                case 2: return issue.Description;
                case 3: return issue.Status;
                case 4: return issue.IssueType;
                case 5: return issue.Owner;
                case 6: return issue.Progress;
                case 7: return issue.CreateTime;
                case 8: return issue.Locked;
            }

        L_012c:
            throw new System.ArgumentOutOfRangeException(name);
        }

        public void SetValue(object obj1, string text1, object obj2)
        {
            Issue issue = obj1 as Issue;
            Dictionary<string, int> dictionary = new Dictionary<string, int>();
            dictionary.Add("IssueID", 0);
            dictionary.Add("Title", 1);
            dictionary.Add("Description", 2);
            dictionary.Add("Status", 3);
            dictionary.Add("IssueType", 4);
            dictionary.Add("Owner", 5);
            dictionary.Add("Progress", 6);
            dictionary.Add("CreateTime", 7);
            dictionary.Add("Locked", 8);
            int num = 0;
            if (dictionary.TryGetValue(text1, out num))
            {
                switch (num)
                {
                    case 0:
                        issue.IssueID = (int)obj2;
                        return;

                    case 1:
                        issue.Title = (string)obj2;
                        return;

                    case 2:
                        issue.Description = (string)obj2;
                        return;

                    case 3:
                        issue.Status = (IssueStatus)obj2;
                        return;

                    case 4:
                        issue.IssueType = (IssueType?)obj2;
                        return;

                    case 5:
                        issue.Owner = (string)obj2;
                        return;

                    case 6:
                        issue.Progress = (decimal?)obj2;
                        return;

                    case 7:
                        issue.CreateTime = (DateTime)obj2;
                        return;

                    case 8:
                        issue.Locked = (bool?)obj2;
                        return;
                }
            }
            throw new ArgumentOutOfRangeException(text1);
        }

        #endregion
    }
}
